import book.Library;
import user.AdminUser;
import user.NormalUser;
import user.ProxyUser;
import user.factory.AdminUserFactory;
import user.factory.IUserFactory;
import user.factory.NormalUserFactory;
import user.User;

import javax.rmi.ssl.SslRMIClientSocketFactory;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-07-03
 * Time: 17:13
 */
public class LibarySystemTest {
   public static void main(String[] args) {
      IUserFactory adminUserfactory = new AdminUserFactory();
      User adim = adminUserfactory.createUser("刘备", 1);
      IUserFactory normalUserfactory = new NormalUserFactory();
      User normal1 = normalUserfactory.createUser("关羽", 2);
      User normal2 = normalUserfactory.createUser("张飞", 3);
      ProxyUser proxyUserAdmin = new ProxyUser(adim);
      ProxyUser proxyUserNormal1 = new ProxyUser(normal1);
      ProxyUser proxyUserNormal2 = new ProxyUser(normal2);
      LibarySystemTest libarySystemTest = new LibarySystemTest();
      ProxyUser currentUser = libarySystemTest.selectProxyRole(proxyUserAdmin, proxyUserNormal1, proxyUserNormal2);
      while(true){
         int choice = currentUser.display(); //对应的角色菜单, 返回角色选择菜单的功能数字， 如1表示xxx
         currentUser.handleOperation(choice); // 对应角色的菜单选择功能实现
      }
   }
   //根据选择的用户让代理对象做出对应代理的类操作
   public ProxyUser selectProxyRole(ProxyUser proxyUserAdmin, ProxyUser proxyUserNormal1, ProxyUser proxyUserNormal2){
      System.out.println("选择⻆⾊进⾏登录：");
      System.out.println("1.管理员\n2.普通⽤⼾(关⽻)\n3.普通⽤⼾(张⻜)\n4.退出系统");
      ProxyUser currentUser = null;
      Scanner scanner = new Scanner(System.in);
      int choice = scanner.nextInt();
      switch (choice){
         case 1:
            currentUser = proxyUserAdmin;
            break;
         case 2:
            currentUser = proxyUserNormal1;
            break;
         case 3:
            currentUser = proxyUserNormal2;
            break;
         case 4:
            System.exit(0);
            System.out.println("退出系统了...");
            break;
         default:
            break;
      }
      return currentUser;
   }
}
